package cn.edu.nwpu.warehousemanagement.controller;

import cn.edu.nwpu.warehousemanagement.config.RsaKeyConfig;
import cn.edu.nwpu.warehousemanagement.pojo.Result;
import cn.edu.nwpu.warehousemanagement.pojo.response.PublicKeyResponse;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Rsa密钥控制类
 *
 * @author Loadstar
 * @version 1.0
 */
@RestController
@RequestMapping("/api")
public class RsaKeyController {
    // 注入密钥配置Bean
    @Resource
    private RsaKeyConfig rsaKeyConfig;

    /**
     * 提供公钥给前端用于加密
     *
     * @return Base64编码的公钥字符串
     */
    @GetMapping("/getPublicKey")
    public Result<PublicKeyResponse> getPublicKey() {
        return Result.success(rsaKeyConfig.getPublicKey());
    }
}

